<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="计划编码" prop="planCode">
        <el-input v-model="queryParams.planCode" placeholder="请输入计划编码" clearable size="small" style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="产线名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入产线名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable size="small" style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable size="small" style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="计划状态" prop="planState">
        <el-select v-model="queryParams.planState" placeholder="请选择计划状态" style="width: 200px"
          @keyup.enter.native="handleQuery">
          <el-option v-for="item in planOptions" :key="item.code" :label="item.name" :value="item.code"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="完工状态" prop="comState">
        <el-select
          v-model="queryParams.comState"
          placeholder="请选择完工状态"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in comOptions"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="工艺路线名称" prop="routingName" label-width="100px">
        <el-input
          v-model="queryParams.routingName"
          placeholder="请输入工艺路线名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="客户订单号" prop="customerOrderNum" label-width="90px">
        <el-input v-model="queryParams.customerOrderNum" placeholder="请输入客户订单号" clearable size="small"
          style="width: 200px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="华为任务令" prop="taskTon" label-width="90px">
        <el-input v-model="queryParams.taskTon" placeholder="请输入华为任务令" clearable size="small" style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['function:prod:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['function:prod:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['function:prod:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['function:prod:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange" style="width: 100%">
      <el-table-column type="selection" width="60" align="center" fixed="left" />
      <el-table-column label="生产计划组件id" align="center" width="100" fixed="left" prop="planId" v-if="false" />
      <el-table-column label="产品编码" align="center" prop="productCode" width="200" fixed="left">
        <template slot-scope="scope">
          <el-button type="text" @click="showDictData(scope.row)">{{ scope.row.productCode }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="产品名称" align="center" prop="productName" width="200" />
      <el-table-column label="计划编码" align="center" prop="planCode" width="100" />
      <el-table-column label="计划数量" align="center" prop="planNumber" width="100" />
      <el-table-column label="华为任务令" align="center" prop="taskTon" width="100" />
      <!-- <el-table-column label="物料编码" align="center" prop="materialCode" width="100" />
      <el-table-column label="物料名称" align="center" prop="materialName" width="200" /> -->
      <!-- <el-table-column label="产线编码" align="center" prop="lineCode" width="100" />
      <el-table-column label="产线名称" align="center" prop="lineName" width="100" /> -->
      <!-- <el-table-column label="工艺路线编码" align="center" prop="routingCode" width="140" /> -->
      <!-- <el-table-column label="工艺路线名称" align="center" prop="routingName" width="200" /> -->
      <el-table-column label="客户编码" align="center" prop="customerCode" width="100" />
      <el-table-column label="客户名称" align="center" prop="customerName" width="200" />
      <el-table-column label="客户订单号" align="center" prop="customerOrderNum" width="120" />
      <el-table-column label="交货日期" align="center" prop="deliveryTime" width="160" />
      <el-table-column label="计划开始时间" align="center" prop="startTime" width="160" />
      <el-table-column label="计划结束时间" align="center" prop="endTime" width="160" />
      <!-- <el-table-column label="完工数量" align="center" prop="comNumber" width="100" /> -->
      <el-table-column label="计划状态" align="center" prop="planState" :formatter="statusFormat" width="100" />
      <!-- <el-table-column label="完工状态" align="center" prop="comState" :formatter="statusFormat1" width="100" /> -->
      <el-table-column label="备注" align="center" prop="remarks" width="200" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="280" fixed="right">
        <template slot-scope="scope">
<!--          <el-button size="mini" type="text" icon="el-icon-edit" style="margin-right: 9px"-->
<!--            @click="handleUpdate(scope.row)" v-hasPermi="['function:prod:edit']">修改</el-button>-->
          <el-button size="mini" type="text" icon="el-icon-delete" style="margin-right: 9px"
            @click="handleDelete(scope.row)" v-hasPermi="['function:prod:remove']">删除</el-button>
          <el-button v-if="scope.row.planState==0||scope.row.planState==1" size="mini" type="text" icon="el-icon-scissors" @click="handleSeparate(scope.row)"
            v-hasPermi="['function:prod:separate']">订单拆分</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改生产计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="760px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">

          <el-col :lg="12">
            <el-form-item label="华为任务令" prop="taskTon">
              <el-input v-model="form.taskTon" placeholder="请输入华为任务令" style="width: 240px" />
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="物料名称" prop="materialCode">
              <el-select
                v-model="form.materialCode"
                placeholder="请选择物料名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in materialOptions"
                  :key="item.materialCode"
                  :label="item.materialName"
                  :value="item.materialCode"
                >
                  <span style="float: left">{{ item.materialCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.materialName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :lg="12">
            <el-form-item label="产线名称" prop="lineCode">
              <el-select
                v-model="form.lineCode"
                placeholder="请选产线名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in lineOptions"
                  :key="item.shopCode"
                  :label="item.shopName"
                  :value="item.shopCode"
                >
                  <span style="float: left">{{ item.shopCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.shopName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="产品名称" prop="productCode">
              <el-select v-model="form.productCode" placeholder="请选产品名称" style="width: 240px">
                <el-option v-for="item in productOptions" :key="item.modelCode" :label="item.ledName"
                  :value="item.modelCode">
                  <span style="float: left">{{ item.modelCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.ledName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="工艺路线名称" prop="routingCode">
              <el-select
                v-model="form.routingCode"
                placeholder="请选择工艺路线名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in routingOptions"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="客户名称" prop="customerCode">
              <el-select v-model="form.customerCode" placeholder="请选择客户名称" style="width: 240px">
                <el-option v-for="item in customerOptions" :key="item.customerCode" :label="item.customerName"
                  :value="item.customerCode">
                  <span style="float: left">{{ item.customerCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.customerName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="客户订单号" prop="customerOrderNum">
              <el-input v-model="form.customerOrderNum" placeholder="请输入客户订单号" style="width: 240px" />
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="完工数量" prop="comNumber">
              <el-input
                v-model="form.comNumber"
                placeholder="请输入完工数量"
                style="width: 240px"
              />
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="计划数量" prop="planNumber">
              <el-input v-model="form.planNumber" placeholder="请输入计划数量" style="width: 240px" />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="计划状态" prop="planState">
              <el-select v-model="form.planState" placeholder="请选择计划状态" style="width: 240px">
                <el-option v-for="item in planOptions" :key="item.code" :label="item.name"
                  :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="完工状态" prop="comState">
              <el-select
                v-model="form.comState"
                placeholder="请选择完工状态"
                style="width: 240px"
              >
                <el-option
                  v-for="item in comOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="交货日期" prop="deliveryTime">
              <el-date-picker v-model="form.deliveryTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间" style="width: 240px"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="12" style="height: 60px">
            <el-form-item label="计划时间" prop="JHTime">
              <el-date-picker v-model="form.JHTime" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间" style="width: 240px"></el-date-picker>
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="计划开始时间" prop="startTime">
              <el-date-picker
                v-model="form.startTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="计划结束时间" prop="endTime">
              <el-date-picker
                v-model="form.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入备注" style="width: 240px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 订单拆分对话框 -->
    <el-dialog :title="separateTitle" :visible.sync="separateOpen" width="760px" append-to-body>
      <el-form ref="formsp" :model="formsp" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :lg="12">
            <el-form-item label="计划编码" prop="planCode">
              <el-input v-model="formsp.planCode" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="华为任务令" prop="taskTon">
              <el-input v-model="formsp.taskTon" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="产品编码" prop="productCode">
              <el-input v-model="formsp.productCode" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="formsp.productName" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="计划数量" prop="planNumber">
              <el-input v-model="formsp.planNumber" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="已下发数量" prop="comNumber">
              <el-input v-model="formsp.comNumber" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="交货日期" prop="deliveryTime">
              <el-input v-model="formsp.deliveryTime" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="创建日期" prop="createTime">
              <el-input v-model="formsp.createTime" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="剩余可下发量" prop="surplusNumber">
              <el-input v-model="formsp.surplusNumber" style="width: 240px" disabled />
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="华为子任务令" prop="orderCode">
              <el-input
                v-model="formsp.orderCode"
                placeholder="请输入任务令"
                style="width: 240px"
              />
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="本次下发数量" prop="orderNumber">
              <el-input-number v-model="formsp.orderNumber" placeholder="请输入下发数量" style="width: 240px" />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="产线名称" prop="lineCode">
              <el-select v-model="formsp.lineCode" placeholder="请选产线名称" style="width: 240px">
                <el-option v-for="item in lineOptions" :key="item.shopCode" :label="item.shopName"
                  :value="item.shopCode">
                  <span style="float: left">{{ item.shopCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.shopName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="工艺路线名称" prop="routingCode">
              <el-select v-model="formsp.routingCode" placeholder="请选择工艺路线名称" style="width: 240px">
                <el-option v-for="item in routingOptions" :key="item.id" :label="item.routingName"
                  :value="item.routingCode">
                  <span style="float: left">{{ item.routingCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.routingName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="15">
            <el-form-item label="计划时间" prop="JHTime">
              <el-date-picker v-model="formsp.JHTime" type="datetimerange" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"
                style="width: 240px"></el-date-picker>
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="计划开始时间" prop="startTime">
              <el-date-picker
                v-model="formsp.startTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="计划结束时间" prop="endTime">
              <el-date-picker
                v-model="formsp.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期时间"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="separateSubmitForm">确 定</el-button>
        <el-button @click="separateCancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="BOM物料清单" :visible.sync="stepsVisible" width="80%" :lock-scroll="false">
      <bom-data :scddErpId="scddErpId" :planCode="planCode"></bom-data>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listPlan,
    getPlan,
    delPlan,
    addPlan,
    updatePlan,
    exportPlan,
    separatePlan,
    listMaterial,
    listProduct,
    listOperations,
    listCustomer,
    getGy
  } from "@/api/function/prod";
  import { getTree } from "@/api/pull/feedSet";
  import bomData from "@/views/components/bomData";

  export default {
    name: "Prod",
    components: { bomData },
    data() {
      return {
        // 遮罩层
        loading: true, planCode: '',
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 生产计划表格数据
        planList: [],
        // 弹出层标题
        title: "",
        separateTitle: "",
        // 是否显示弹出层
        open: false,
        separateOpen: false,
        // scddErpId
        scddErpId: "",
        // 生产table弹窗
        stepsVisible: false,
        // 计划状态下拉框
        planOptions: [
          { code: 0, name: '新建' },
          { code: 1, name: '已拆分' },
          { code: 2, name: '已关闭' }
        ],
        // 完工状态下拉框
        comOptions: [
          { code: 0, name: '未完成' },
          { code: 1, name: '已完成' }
        ],
        // 物料名称下拉框
        materialOptions: [],
        // 产线名称下拉框
        lineOptions: [],
        // 产品名称下拉框
        productOptions: [],
        // 工艺名称下拉框
        routingOptions: [],
        // 客户名称下拉框
        customerOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          planCode: undefined,
          customerName: undefined,
          productName: undefined,
          planState: undefined,
          customerOrderNum: undefined,
          taskTon: undefined,

        },
        // 表单参数
        form: {},
        // 拆分
        formsp: {},
        // 表单校验
        rules: {
          planCode: [{ required: true, message: "计划编码不能为空", trigger: "change" }],
          planNumber: [{ required: true, message: "计划数量不能为空", trigger: "change" }],
          taskTon: [{ required: true, message: "华为任务令不能为空", trigger: "change" }],
          productCode: [{ required: true, message: "产品名称不能为空", trigger: "change" }],
          customerCode: [{ required: true, message: "客户名称不能为空", trigger: "change" }],
          customerOrderNum: [{ required: true, message: "客户订单号不能为空", trigger: "change" }]
        }
      };
    },
    created() {
      this.getMaterialList();
      this.getLineList();
      this.getProductList();
      this.getRoutingList();
      this.getCustomerList();
      this.getList();
    },
    methods: {
      /** 查询生产计划列表 */
      getList() {
        this.loading = true;
        listPlan(this.queryParams).then(response => {
          this.planList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 查询物料下拉
      getMaterialList() {
        listMaterial({}).then(response => {
          this.materialOptions = response;
        });
      },
      // 查询产线下拉
      getLineList() {
        getTree(3).then(response => {
          this.lineOptions = response.data;
        });
      },
      // 查询产品下拉
      getProductList() {
        listProduct({}).then(response => {
          this.productOptions = response.data;
        });
      },
      // 查询工艺下拉
      getRoutingList() {
        listOperations({}).then(response => {
          this.routingOptions = response;
        });
      },
      // 查询客户下拉
      getCustomerList() {
        listCustomer({}).then(response => {
          this.customerOptions = response;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 取消按钮
      separateCancel() {
        this.separateOpen = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {};
        this.resetForm("form");
      },
      resetsp() {
        this.formsp = {};
        this.resetForm("formsp");
      },
      // 状态查询
      statusFormat(row, column) {
        let str = '';
        switch (row.planState) {
          case 0:
            str = '新建'
            break;
          case 1:
            str = '已拆分'
            break;
          case 2:
            str = '已关闭'
            break;
             case 3:
            str = '弃审'
            break;
          default: console.log('no default');
        }
        return str;
      },
      statusFormat1(row, column) {
        let str = '';
        switch (row.comState) {
          case 0:
            str = '未完成'
            break;
          case 1:
            str = '已完成'
            break;
          default: console.log('no default');
        }
        return str;
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.planId);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      // table弹框
      showDictData(row) {
        this.scddErpId = row.scddErpId;
        this.planCode = row.planCode;
        this.stepsVisible = true;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加生产计划";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const planId = row.planId || this.ids;
        getPlan(planId).then(response => {
          if (response.data.startTime) {
            response.data.JHTime = [response.data.startTime, response.data.endTime];
          };
          this.form = response.data;
          this.open = true;
          this.title = "修改生产计划";
        });
      },
      /** 拆分按钮操作 */
      handleSeparate(row) {
        this.resetsp();
        const planId = row.planId;
        getPlan(planId).then(response => {
          if (response.data.startTime) {
            response.data.JHTime = [response.data.startTime, response.data.endTime];
          };
          this.formsp = response.data;
          this.separateOpen = true;
          this.separateTitle = '生产订单拆分';
        });

        //更新工艺数据
        getGy(planId).then(response => {
          this.routingOptions = response.data;
        });

      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.JHTime) {
              this.form.startTime = this.form.JHTime[0];
              this.form.endTime = this.form.JHTime[1];
            };
            if (this.form.planId != null) {
              updatePlan(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addPlan(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 提交按钮 */
      separateSubmitForm() {
        this.$refs["formsp"].validate(valid => {
          if (valid) {
            if (this.formsp.JHTime) {
              this.formsp.startTime = this.formsp.JHTime[0];
              this.formsp.endTime = this.formsp.JHTime[1];
            };
            separatePlan(this.formsp).then(response => {
              if (response.code === 200) {
                this.msgSuccess("拆分成功");
                this.separateOpen = false;
                this.getList();
              }
            });
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const planIds = row.planId || this.ids;
        this.$confirm('是否确认删除生产计划编号为"' + planIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delPlan(planIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function () { });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有生产计划数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return exportPlan(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function () { });
      }
    }
  };
</script>
